
import zhipuai

zhipuai.api_key = "41805a5412196acfdd9d63a905f9039a.Z0TWy2173NoP1ZkI"
response = zhipuai.model_api.sse_invoke(
    model="chatglm_lite",
    prompt= [{"role":"user","content":"请以“ChatGLM帮你自动写文案”为主题生成几个小红书标题，需遵循以下要求：\n1.标题长度不得超过20个字。\n2.标题应具有吸引人的特点，能够吸引目标受众。\n3.标题要与文章主题紧密相关，以便读者更好地了解文章内容。\n4.符合小红书风格，语气亲近且自然"}],
    temperature= 0.9,
    top_p= 0.7,
    incremental=True
)

for event in response.events():
    if event.event == "add":
        print(event.data, end="")
    elif event.event == "error" or event.event == "interrupted":
        print(event.data, end="")
    elif event.event == "finish":
        print(event.data)
        print(event.meta, end="")
    else:
        print(event.data, end="")